﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.ComponentModel;

namespace ViCode_LeVi.Configs
{
    [DataContract]
    public class VMConfig
    {
        public const string PATH_VMConfig = "config.vmconfig";
        static VMConfig _Intance = null;
        public static VMConfig Intance
        {
            get
            {
                if (_Intance == null)
                {
                    //Read Config
                    string sPath = System.IO.Path.Combine(FileFolder.AppInfo.AppDirectory, "Configs/" + PATH_VMConfig);
                    if (!string.IsNullOrEmpty(sPath) && System.IO.File.Exists(sPath))
                    {
                        _Intance = XMLDataSerializer.XMLData<VMConfig>.GetEntity(sPath);
                    }
                    //If NULL
                    if (_Intance == null || _Intance.TaskItem_Quantity_Image_Item == null || _Intance.Colors== null)
                    {
                        //Default
                        _Intance = new VMConfig();
                        _Intance.TaskItem_Quantity_Image_Item = new TaskItem_Quantity_Image() { Level1 = 30, Level2 = 59, Level3 = 100 };

                        
                        //Save config  
                        string sFolder = System.IO.Path.GetDirectoryName(sPath);
                        FileFolder.FolderHelper.EnsureExistFolder(sFolder);
                        if (System.IO.File.Exists(sPath))
                            System.IO.File.Delete(sPath);
                        XMLDataSerializer.XMLData<VMConfig>.SaveEntity(sPath, _Intance);
                    }
                    _Intance.Colors = new VMConfigColor()
                    {
                        BK = System.Drawing.Color.FromArgb(255, 255, 255, 192),
                        HK = System.Drawing.Color.FromArgb(255, 255, 192, 255),
                        SK = System.Drawing.Color.FromArgb(255, 255, 224, 192),
                        ChartBad = System.Drawing.Color.FromArgb(255, 255, 192, 192),
                        ChartMedium = System.Drawing.Color.FromArgb(255, 255, 255, 192),
                        ChartGood= System.Drawing.Color.FromArgb(255, 192, 255, 192)
                        ,
                                                            QL = System.Drawing.Color.FromArgb(255, 192, 192, 255),
                                                            QN = System.Drawing.Color.FromArgb(255, 222, 184, 135),
                                                            SY = System.Drawing.Color.FromArgb(255, 143, 188, 139)
                    };

                    _Intance.Charts = new VMConfigChart()
                    {
                         AllowMultiplePreviews= true,
                          ShowEmptyCharts = 0,
                           ShowMissingChartsWarning = true,
                            MaximiseReports= true,
                             BarChartHatching = true,
                              BarChartTransparency = 50,
                               LimitBarChartBarWidth = true,
                                MaxBarChartBarWidth=50
                    };

                    _Intance.ExpertMode = new VMConfigExpertMode()
                    {
                        ShowHtmlExportOption = true,
                         ShowRtfExportOption = true,
                          ShowSendAsMailExportOption = true   ,
                    };
                    _Intance.UIFont = new VMConfigUIFont() 
                    {
                         TextBlock_FontName ="Arial",
                          TextBlock_FontSize = 13,
                           TextBox_FontName ="Arial",
                            TextBox_FontSize=13
                    };
                }
                return _Intance;
            }
        }
        #region TaskItem_Quantity_Image_Item
        TaskItem_Quantity_Image _TaskItem_Quantity_Image_Item = null;
        [DataMember]
        public TaskItem_Quantity_Image TaskItem_Quantity_Image_Item 
        {
            get 
            {
                if (_TaskItem_Quantity_Image_Item == null)
                    _TaskItem_Quantity_Image_Item = new TaskItem_Quantity_Image() { Level1 = 30, Level2 = 59, Level3 = 100 };
                return _TaskItem_Quantity_Image_Item;
            }
            set { _TaskItem_Quantity_Image_Item = value; }
        }
        #endregion

        #region VMConfig_Step_TaskItem_Default
        VMConfig_Step_RiskManagementItem_Default _VMConfig_Step_RiskManagementItem_Default_Item = null;
        [DataMember]
        public VMConfig_Step_RiskManagementItem_Default VMConfig_Step_RiskManagementItem_Default_Item
        {
            get
            {
                if (_VMConfig_Step_RiskManagementItem_Default_Item == null)
                    _VMConfig_Step_RiskManagementItem_Default_Item = new VMConfig_Step_RiskManagementItem_Default() ;
                return _VMConfig_Step_RiskManagementItem_Default_Item;
            }
            set { _VMConfig_Step_RiskManagementItem_Default_Item = value; }
        }
        #endregion

        #region VMConfig_Step_TaskItem_Default
        VMConfig_Step_TaskItem_Default _VMConfig_Step_TaskItem_Default_Item = null;
        [DataMember]
        public VMConfig_Step_TaskItem_Default VMConfig_Step_TaskItem_Default_Item
        {
            get
            {
                if (_VMConfig_Step_TaskItem_Default_Item == null)
                    _VMConfig_Step_TaskItem_Default_Item = new VMConfig_Step_TaskItem_Default() { Name = "New Title", Define = "New Defination", Active = true, Weight = 0 };
                return _VMConfig_Step_TaskItem_Default_Item;
            }
            set { _VMConfig_Step_TaskItem_Default_Item = value; }
        }
        #endregion
        public VMConfigColor Colors { get; set; }
        [DataMember]
        public VMConfigChart Charts { get; set; }
        [DataMember]
        public VMConfigExpertMode ExpertMode { get; set; }

        [DataMember]
        public VMConfigUIFont UIFont { get; set; }
    }

    [DataContract]
    public class VMConfigUIFont
    {
        [DataMember]
        public string TextBlock_FontName { get; set; }
        [DataMember]
        public double TextBlock_FontSize { get; set; }
        [DataMember]
        public string TextBox_FontName { get; set; }
        [DataMember]
        public double TextBox_FontSize { get; set; }
    }

    public class BTB_DH
    {
        public const double INVALID_DOUBLE = double.MinValue;
        public const double INVALID_INT = int.MinValue;
        public static DateTime INVALID_DATE = DateTime.MinValue;
    }

    [DataContract]
    public class VMConfigExpertMode
    {
        [DataMember]
        public bool ShowHtmlExportOption { get; set; }
        [DataMember]
        public bool ShowRtfExportOption { get; set; }
        [DataMember]
        public bool ShowSendAsMailExportOption { get; set; }
        
            
    }
    [DataContract]
    public class VMConfigChart
    {
        [DataMember]
        public int ShowEmptyCharts { get; set; }
        [DataMember]
        public bool ShowMissingChartsWarning { get; set; }
        [DataMember]
        public bool AllowMultiplePreviews { get; set; }
        [DataMember]
        public bool MaximiseReports { get; set; }
        [DataMember]
        public bool BarChartHatching { get; set; }
        [DataMember]
        public bool LimitBarChartBarWidth { get; set; }
        [DataMember]
        public float MaxBarChartBarWidth { get; set; }
        
        [DataMember]
        public int BarChartTransparency { get; set; }
    }

    [DataContract]
    public class VMConfigColor
    {
        public System.Drawing.Color HK { get; set; }
        public System.Drawing.Color BK { get; set; }
        public System.Drawing.Color SK { get; set; }
        public System.Drawing.Color ChartBad { get; set; }     
        public System.Drawing.Color ChartMedium { get; set; }
        public System.Drawing.Color ChartGood { get; set; }   
        public System.Drawing.Color QN { get; set; }     
        public System.Drawing.Color QL { get; set; }
        public System.Drawing.Color SY { get; set; }   
    }

    [DataContract]
    public class VMConfig_Step_TaskItem_Default : INotifyPropertyChanged
    {
        #region Name
        string _Name = "";
        [DataMember]
        public string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                if (value != _Name)
                {
                    _Name = value;
                    SendPropertyChanged("Name");
                }
            }
        }
        #endregion

        #region Define
        string _Define = "";
        [DataMember]
        public string Define
        {
            get
            {
                return _Define;
            }
            set
            {
                if (value != _Define)
                {
                    _Define = value;
                    SendPropertyChanged("Define");
                }
            }
        }
        #endregion

        #region Weight
        int _Weight = 0;
        [DataMember]
        public int Weight
        {
            get
            {
                return _Weight;
            }
            set
            {
                if (value != _Weight)
                {
                    _Weight = value;
                    SendPropertyChanged("Weight");
                }
            }
        }
        #endregion

        #region Active
        bool _Active = true;
        [DataMember]
        public bool Active
        {
            get
            {
                return _Active;
            }
            set
            {
                if (value != _Active)
                {
                    _Active = value;
                    SendPropertyChanged("Active");
                }
            }
        }
        #endregion

        #region INotifyPropertyChanged Members
        public void SendPropertyChanged(string sProp)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(sProp));
        }
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion   
    }

    [DataContract]
    public class VMConfig_Step_RiskManagementItem_Default : INotifyPropertyChanged
    {
        #region RiskNo
        private long _RiskNo;
        /// <summary>
        /// Mức do quan trong
        /// </summary>
        [DataMember]
        public long RiskNo
        {
            get { return _RiskNo; }
            set
            {
                if (_RiskNo != value)
                {
                    _RiskNo = value;
                    SendPropertyChanged("RiskNo");
                }
            }
        }
        #endregion

        #region Risk
        private string _Risk = "New Risk";
        /// <summary>
        /// Mức do quan trong
        /// </summary>
        [DataMember]
        public string Risk
        {
            get { return _Risk; }
            set
            {
                if (_Risk != value)
                {
                    _Risk = value;
                    SendPropertyChanged("Risk");
                }
            }
        }
        #endregion

        #region Impact
        private int _Impact = 1;
        /// <summary>
        /// Mức do quan trong
        /// </summary>
        [DataMember]
        public int Impact
        {
            get { return _Impact; }
            set
            {
                if (_Impact != value)
                {
                    _Impact = value;
                    SendPropertyChanged("Impact");
                }
            }
        }
        #endregion

        #region Manage
        private string _Manage = "New Manage";
        /// <summary>
        /// Mức do quan trong
        /// </summary>
        [DataMember]
        public string Manage
        {
            get { return _Manage; }
            set
            {
                if (_Manage != value)
                {
                    _Manage = value;
                    SendPropertyChanged("Manage");
                }
            }
        }
        #endregion

        #region Probability
        private int _Probability = 1;
        /// <summary>
        /// Mức do quan trong
        /// </summary>
        [DataMember]
        public int Probability
        {
            get { return _Probability; }
            set
            {
                if (_Probability != value)
                {
                    _Probability = value;
                    SendPropertyChanged("Probability");
                }
            }
        }
        #endregion

        #region INotifyPropertyChanged Members
        public void SendPropertyChanged(string sProp)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(sProp));
        }
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
    [DataContract]
    public class VMDeisgnUIInfo
    {
        public static VMDeisgnUIInfo Intance = new VMDeisgnUIInfo()
        {
            NewGroupQuestionAnswer = "Nhóm câu hỏi mới",
            NewAnswer = "Câu hỏi mới",
            NewQuestion = ""
        };
        [DataMember]
        public string NewGroupQuestionAnswer { get; set; }
        [DataMember]
        public string NewAnswer { get; set; }
        [DataMember]
        public string NewQuestion { get; set; }
    }
}
